#include <data_structure_design/linked_list.h>

        LinkedList::LinkedList()
        {
           *head = null;
        }
        void LinkedList::push_front( double const & a)
     
        {
          LinkedListNode *new;
          new.data = a;
          new.next = head;
          head = new;
        }
        void LinkedList::push_back( double const & a)
        
        {
          LinkedListNode *new;
          new.data = a;
          new.next = null;
          while (head.next != null)
          {
            head = head.next;
          }
          head.next = new;
        }
        <LinkedListNode> LinkedList::begin()
        {
          LinkedListNode *new;
          new.data = head.data;
          new.next = head.next;
          return *new;
        }
        <LinkedListNode> LinkedList::end()
        {
          LinkedListNode *new;
          while (head.next != null)
          {
            head = head.next;
          }
          new.data = head.data;
          new.next = head.next;
          return *new;
        }
        double & LinkedList::front() 
        {
          double & value = head.data;
          return (value);
        }
        double & LinkedList::back()
        {
          while (head.next != null)
          {
            head = head.next;
          }
          double & value = head.data;
          return (value);
        }
        /*! In this part of the program, the code search the linked list for the given node to insert the given value as a node before it, but if the program doesn't find the given node, it will cout that the given node doesn't exist
        */
        <LinkedListNode> LinkedList::insert( double const & a, <LinkedListNode> b )
        
        {
          flag f = false; 
          LinkedListNode *tmp;
          LinkedListNode *new;
          new.data = a;
          tmp = head;
          while ((tmp.data != b.data) ||(tmp.next != null))
          { 
            if(tmp.data == b.data) {flag = true;}
            head = tmp;
            tmp = tmp.next;
          }
          if (flag == false) 
          {
          std::cout<< "The given node doesn't exist" << std::endl;
           return 0;
           }
          else
          {new.next = tmp;
          new = head.next;
          return *new;
          }
        }
        /*! in this part we initialize the count with 1 in case we have just one node */
        unsigned int LinkedList::size()// return the number of elements in the list
        {
         unsigned int count = 1;
          while (head.next != null)
          {
            head = head.next;
            count++;
          }
          return count;
        }
